<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('鉴定受理登记列表')"/>
    <th:block th:include="include :: bootstrap-select-css"/>

</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <input type="hidden" name="userId" id="userId" th:value="*{userId}"/>
            <input type="hidden" name="grouper" id="grouper" th:value="*{grouper}"/>
            <!--                是审核组长  为1 不是为0-->
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>送鉴单位：</label>
                            <input type="text" name="sendUnit"/>
                        </li>
                        <li>
                            <label>来文文号：</label>
                            <input type="text" name="documentNum"/>
                        </li>
                        <li>
                            <label>鉴定内容：</label>
                            <input type="text" name="identContent"/>
                        </li>
                        <!--<li class="select-time">
                            <label>送鉴日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginSendDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endSendDate]"/>
                        </li>
                        <li class="select-time">
                            <label>受理日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginAcceptDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endAcceptDate]"/>
                        </li>-->

                        <li>
                            <label>样本类别：</label>
                            <!--                                <input type="text" name="category"/>-->
                            <!--<select name="category" class=" noselect2 selectpicker" th:with="type=${@dict.getType('re_review_scope')}" data-none-selected-text="请选择审读范围" >
                                <option value="">所有</option>

                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>-->
                            <select name="category" th:with="type=${@dict.getType('id_sample_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <!--审核状态 1:未通过 3:待审核 5:通过-->

                        <li>
                            <label>状态：</label>
                            <select name="auditStatus">
                                <option value="">所有</option>


                                <option value="3">草稿</option>
                                <option value="4">待审核</option>
                                <option value="5">通过</option>
                                <option value="1">不通过</option>
                                <option value="6">完结</option>
                            </select>
                        </li>
                        <!--<li>
                            <label>是否启用：</label>
                            <select name="isUse">
                                <option value="1">开启</option>
                                <option value="0">关闭</option>
                            </select>
                        </li>-->

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="$.operate.editTab()" shiro:hasPermission="publish:paperwork:edit">
                <i class="fa fa-plus"></i> 编辑文书
            </a>
            <!--                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="publish:register:edit" >-->
            <!--                    <i class="fa fa-edit"></i> 修改-->
            <!--                </a>-->
            <!-- <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="publish:register:remove">
                 <i class="fa fa-remove"></i> 删除
             </a>-->
            <!--<a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="publish:register:import">-->
                <!--<i class="fa fa-upload"></i> 导入-->
            <!--</a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcelRecord('formId')" shiro:hasPermission="publish:register:export">-->
                <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-select-js"/>

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('publish:register:edit')}]];
    var removeFlag = [[${@permission.hasPermi('publish:register:remove')}]];
    var examineFlag = [[${@permission.hasPermi('publish:register:examine')}]];


    var prefix = ctx + "publish/paperwork";
    var formData = {};
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            //anotherUrl: "/publish/identsample/listByRegister",
            selectAssistUrl: "/publish/identsample/identsampleByAssist",
            selectIdReport: prefix+"/reportByRegister",
            anotherUrl: "/publish/paperwork/detail",
            acceptUrl: "/sys/word/accept/",
            registerUrl: "/sys/word/register/",
            assistUrl: "/sys/word/assist/",
            deliverUrl: "/sys/word/deliver/", //送达登记表
            refreshUrl: "/publish/register/refresh/{id}", //一键更新
            approvalhistoryUrl: "/publish/record/detail/{id},2",
            checkDeliverUrl:"/publish/register/checkDeliver",
            detailUrl: prefix + "/detail/{id}",

            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",

            sortName: "createTime",
            sortOrder: "desc",
            modalName: "文书信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                // {
                //     field: 'index',
                //     align: 'center',
                //     title: "序号",
                //     formatter: function (value, row, index) {
                //         var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                //         return columnIndex + $.table.serialNumber(index);
                //     }
                // },

                {
                    field: 'createBy',
                    title: '创建人工号',
                    visible: false
                },
                {
                    field: 'updateName',
                    title: '更新姓名',
                    visible: false
                },
                {
                    field: 'updateBy',
                    title: '更新人工号',
                    visible: false
                },
                {
                    field: 'sendUnitId',
                    title: '送鉴单位',
                    visible: false,
                    sortable: true,
                },
                {
                    field: 'sendUnit',
                    title: '送鉴单位',
                    sortable: true,
                },
                {
                    field: 'title',
                    title: '来文标题',
                    visible: false,
                    sortable: true,
                },
                {
                    field: 'documentNum',
                    title: '来文文号',
                    sortable: true,
                },
                {
                    field: 'ex1',
                    title: '编号',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'sendDate',
                    title: '送鉴日期',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.common.dateFormatConver(value,false,'-');
                    },
                    sortable: true,
                },
                {
                    field: 'category',
                    title: '样本类别',
                    sortable: true,
                },
                {
                    field: 'createName',
                    title: '创建人',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'acceptDate',
                    title: '受理日期',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.common.dateFormatConver(value,false,'-');
                    },
                    sortable: true,
                },
                {
                    field: 'groupId',
                    title: '鉴定组长id',
                    visible: false
                },
                {
                    field: 'groupLeader',
                    title: '鉴定组长',
                    align: 'center',
                    sortable: true,
                },
                {
                    field: 'identContent',
                    title: '鉴定内容',
                    visible: false
                },
                {
                    field: 'files',
                    title: '来函文件',
                    visible: false
                },
                {
                    field: 'types',
                    title: '样本种类数量',
                    visible: false
                },
                {
                    field: 'num',
                    title: '样本数量',
                    visible: false
                },
                {
                    field: 'auditStatus',
                    title: '状态',
                    align: 'center',

                    formatter: function (value, row, index) {
                        var text = '';
                        value = Number(value);
                        switch (value) {
                            case 1:
                                text = '不通过';
                                break;
                            case 3:
                                text = '草稿';
                                break;
                            case 4:
                                text = '待审核';
                                break;
                            case 5:
                                text = '通过';
                                break;
                            case 6:
                                text = '完结';
                                break;
                        }
                        return text;
                    },
                    sortable: true,

                },
                {
                    field: 'isUse',
                    title: '是否启用',
                    visible: false,
                    align: 'center',

                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },

                {
                    field: 'ex2',
                    title: '备用字段',
                    visible: false
                },
                {
                    field: 'ex3',
                    title: '备用字段',
                    visible: false
                },
                {
                    field: 'ex4',
                    title: '备用字段',
                    visible: false
                },
                {
                    field: 'ex5',
                    title: '备用字段',
                    visible: false
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [], more = [];
                        // actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.openTab(\'' + '鉴定样本' + '\',\'' + table.options.anotherUrl + '?registerId=' + row.id + '\')"><i class="fa fa-search"></i>查看文书</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.openTab(\'' + '查看文书' + '\',\'' + table.options.anotherUrl + '?id=' + row.id + '\')"><i class="fa fa-search"></i>查看文书</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.openTab(\'' + '相关协查函' + '\',\'' + table.options.selectAssistUrl + '?registerId=' + row.id + '\')"><i class="fa fa-search"></i>协查函</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.openTab(\'' + '相关鉴定报告' + '\',\'' + table.options.selectIdReport + '?registerId=' + row.id + '\')"><i class="fa fa-search"></i>鉴定结论</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function openWinUser(id, groupId) {
        formData.id = id;
        if (groupId == null || groupId == "") {
            groupId = 0;
        }
        $.modal.open("选择鉴定组长", "/system/user/userGroupSelect/" + groupId);
    }

    function stringEqual(paramsUser, user) {
        var result = false;
        if ($.common.isNotEmpty(paramsUser) && $.common.isNotEmpty(user)) {
            if (Number(paramsUser) == Number(user)) {
                result = true;
            }
        }
        return result;
    }

    // 增加审批人的选择
    function setUser(rows) {
        if (rows != null && rows.length > 0) {
            formData.groupId = rows[0].userId;
            formData.groupLeader = rows[0].userName;
            // 设置为待审核
            formData.auditStatus = 4;
            submitSelect();
        }

        // 提交选择人信息
        function submitSelect() {
            $.ajax('/publish/register/edit', {
                type: "post",
                timeout: 30000,
                data: formData,
                success: function (res) {
                    if (res.code == 0) {
                        layer.alert("添加送审成功!");
                        addApprovalUser();
                    }
                },
                error: function (res) {
                    console.log(res);
                }
            });
        }
    }


    // 添加送审人员信息
    function addApprovalUser() {
        var formUserData = {};
        formUserData.recordId = formData.id;
        formUserData.systemModule = 2;
        formUserData.approvalReason = formData.groupId + "|" + formData.groupLeader;
        // 送审人员
        formUserData.approvalType = 1;
        formUserData.approvalStatus = 1;
        // 送审消息
        formUserData.approvalTitle = "送审鉴定组长";

        $.ajax('/publish/record/addApprovalUser', {
            type: "post",
            timeout: 3000,
            data: formUserData,
            success: function (res) {
                if (res.code == 0) {
                    $.table.refresh();
                }
            },
            error: function (res) {
                console.log(res);
            }
        });
    }

    function windOpens(num, id, wordid) {
        console.log(num)
        if (num == 1) {//受理通知书
            window.open(table.options.acceptUrl + id)

        } else if (num == 2) {//鉴定登记表
            window.open(table.options.registerUrl + id)

        } else if (num == 3) {
            console.log(id)
            $.ajax({
                type: "POST",
                url: table.options.checkDeliverUrl,
                data: 'id='+id,
                cache: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.open(table.options.deliverUrl + id)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });

        } else if (num == 4) {//协查函
            //为空提醒选择  现在都显示
            // if($.common.isEmpty(wordid)){
            assisAlter(id)
            // }else{
            //     window.open(table.options.assistUrl+id)
            // }
        } else if (num == 5) {
            table.set();
            $.modal.confirm("确定要更新该条记录所有的文档吗？", function () {
                var url = $.common.isEmpty(id) ? table.options.refreshUrl : table.options.refreshUrl.replace("{id}", id);
                if (table.options.type == table_type.bootstrapTreeTable) {
                    $.operate.get(url);
                } else {
                    var data = {"id": id};
                    $.operate.submit(url, "post", "json", data);
                }
            });
        }

    }

    function windOpen(url) {
        window.open(url)
    }

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.isUse == '0') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 是否启用-关闭 */
    function disable(id) {
        $.modal.confirm("确认要关闭吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "isUse": '0'});
        })
    }

    /* 是否启用-开启 */
    function enable(id) {
        $.modal.confirm("确认要开启吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "isUse": '1'});
        })
    }

    /* 完结 */
    function end(id) {
        $.operate.post(prefix + "/changeStatus", {"id": id, "auditStatus": 6});
    }

    /* 审核 */
    function audit(id) {
        var options = {
            title: '登记审核',
            width: "550",
            height: "300",
            url: prefix + "/audit",
            callBack: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                /*审核状态 1:未通过 3:待审核 5:通过*/
                var auditStatus = body.find('input[name="auditStatus"]:checked').val();
                var remark = body.find('[name="remark"]').val();
                /*审核不通过时为空*/
                if (auditStatus == '1') {
                    // remark = '';
                }
                $.operate.post(prefix + "/handle", {"id": id, "auditStatus": auditStatus, "approvalReason": remark,"remark":remark});
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }


    function openWindow(url) {
        window.open(url)
    }


    // 导入数据
    function assisAlter(id) {
        table.set();
        var currentId = 'assitCheck';
        layer.open({
            type: 1,
            area: ['300px', '200px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '协查函类型选择',
            content: $('#' + currentId).html(),
            btn: ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function (index, layero) {
                var file = layero.find('input[name="yesNo"]:checked').val();

                // var index = layer.load(2, {shade: false});
                // $.modal.disable();
                // var formData = new FormData(layero.find('form')[0]);

                console.log(file)
                $.modal.closeAll();
                $.table.refresh();

                window.open(table.options.assistUrl + id + "?yesNo=" + file)

            }
        });
    }


</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <!--                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据-->
                <input type="number" th:value="${year}" id="year" name="year" title="请输入对应年份" th:max="${year}">

                &nbsp; <a href="/excelTemplate/register/案件管理模板.xlsx" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>


<!-- 送达单 -->
<script id="assitCheck" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <div class="mt10 pt5">
                <input type="radio" value="no" name="yesNo" title="无附件" checked> 无附件
                <input type="radio" value="yes" name="yesNo" title="有附件"> 有附件

            </div>

        </div>
    </form>
</script>
</html>
